<?php
namespace Mobile\Controller;

use Common\Controller\UserBaseController;

/**
 * 足彩控制器
 */
class SportController extends UserBaseController
{
    public function _initialize()
    {
        parent::_initialize();

    }
    /**
     * 首页
     */
    public function index()
    {

        $this->display();
    }
    public function balance()
    {
        $info = D('Member')->getOneMember($_SESSION['member_id']);

        $info['money']  = $info['member_money'] + $info['member_f_money'];
        $data['result'] = $info['money'];
        $this->ajaxReturn($data);
    }
    public function head()
    {

        $info = D('Member')->getOneMember($_SESSION['member_id']);

        $info['betting'] = M('lottery_order')->where('m_id=' . $_SESSION['member_id'] . ' and status=0')->sum('money');
        if (empty($info['betting'])) {
            $info['betting'] = 0;
        }
        $info['money'] = $info['member_money'] + $info['member_f_money'];
        $this->assign('info', $info);
        $this->display();
    }
    public function left()
    {

        $this->display();
    }

    //赛事
    public function match()
    {
        $stype = $_GET['stype'];
        if (empty($stype)) {
            $stype = 'ft';
        }
        $type = $_GET['type'];
        if (empty($type)) {
            $type = 'ds';
        }
        $dtype = $_GET['dtype'];
        if (empty($dtype)) {
            $dtype = 'today';
        }
        switch ($type) {
            case 'gq':
                $type_name = '滚球';
                break;
            case 'zrq':
                $type_name = '入球数';
                break;
            case 'bd':
                $type_name = '波胆';
                break;
            case 'bqs':
                $type_name = '半全场';
                break;
            case 'zhgg':
                $type_name = '综合过关';
                break;

            default:
                $type_name = '单式';
                break;
        }
        switch ($stype) {
            case 'bb':
                $stype_name = '篮球';
                break;

            default:
                $stype_name = '足球';
                break;
        }

        $leagues = M('sport_league')->where("is_show=1 and stype='" . $stype . "'")->select();
        foreach ($leagues as $k => $v) {
            $leagues[$k]['count'] = M('sport_result_' . $type)->where("status=0 and league_id=" . $v['id'] . " and stype='" . $stype . "'")->count();
        }
        $this->assign('leagues', $leagues);

        $this->assign('type', $type);
        $this->assign('stype', $stype);
        $this->assign('dtype', $dtype);

        $this->assign('title', $stype_name . '-' . $type_name);
        if ($type == 'zhgg') {
            $this->display('match_zhgg');
        } else {
            $this->display();
        }

    }
    //赛事内容
    public function match_detail()
    {
        $m_id       = $_GET['m_id'];
        $match_name = M('sport_league')->where('id=' . $m_id)->getField('match_name');
        $type       = $_GET['type'];
        if (empty($type)) {
            $type = 'ds';
        }
        switch ($type) {
            case 'gq':
                $type_name = '滚球';
                break;
            case 'zrq':
                $type_name = '入球数';
                break;
            case 'bd':
                $type_name = '波胆';

                break;
            case 'bqs':
                $type_name = '半全场';
                break;
            case 'zhgg':
                $type_name = '综合过关';
                break;

            default:
                $type_name = '单式';
                break;
        }
        $stype = $_GET['stype'];
        if (empty($stype)) {
            $stype = 'ft';
        }
        $list = M('sport_result_' . $type)->where("status=0 and league_id=" . $m_id)->select();
        $this->assign('list', $list);

        $this->assign('type', $type);

        $this->assign('stype', $stype);
        $this->assign('title', $match_name . '-' . $type_name);
        $this->display('match_detail_' . $type);
    }

    //比赛结果
    public function match_result()
    {
        $stype = $_GET['stype'];
        if (empty($stype)) {
            $stype = 'ft';
        }

        if ($stype == 'ft') {
            $this->assign('title', '足球赛果');
        } else {
            $this->assign('title', '篮球赛果');
        }

        $this->assign('stype', $stype);
        $this->display();
    }

    //体育公告
    public function membermessage()
    {

        $this->assign('title', '体育公告');
        $this->display();
    }

    public function ft()
    {

        $btype = $_GET['btype'];
        if (empty($btype)) {
            $btype = 'gq';
        }

        //联赛
        $leagues = M('sport_league')->where("is_show=1 and stype='ft'")->select();
        $this->assign('leagues', $leagues);

        $result = M('sport_result_' . $btype); // 实例化User对象
        $count  = $result->where("status=0 and stype='ft'")->count(); // 查询满足要求的总记录数
        $Page   = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show   = $Page->show(); // 分页显示输出
        $list   = $result->where("status=0 and stype='ft'")->limit($Page->firstRow . ',' . $Page->listRows)->select();

        foreach ($list as $key => $value) {
            $list_new[$value['league_id']]['list'][]     = $value;
            $list_new[$value['league_id']]['match_name'] = $value['match_name'];

            //     if($value['final_score']!=''){
            //     $list_new[$value['league_id']]['list'][]['score']=$value['final_score'];
            // }else{
            //     $list_new[$value['league_id']]['list'][]['score']="上35'<br><span>2 - 0</span>";
            //     //$list[$k]['score']=$v['half_score'];
            // }

        }
        //print_r($list_new);exit;
        $this->assign('list', $list_new);
        $this->assign('page', $show); // 赋值分页输出

        $this->display('ft_' . $btype);
    }
    //获取球赛数量
    public function count()
    {
        //滚球-足球
        $data['gq']   = M('sport_result_gq')->where("stype='ft' and status=0")->count();
        $data['ds']   = M('sport_result_ds')->where("stype='ft' and status=0")->count();
        $data['zhgg'] = M('sport_result_zhgg')->where("stype='ft' and status=0")->count();
        $data['bd']   = M('sport_result_bd')->where("status=0")->count();
        $data['zrq']  = M('sport_result_zrq')->where("status=0")->count();
        $data['bqs']  = M('sport_result_bqs')->where("status=0")->count();

        //篮球
        $data['bb_gq']   = M('sport_result_gq')->where("stype='bb' and status=0")->count();
        $data['bb_ds']   = M('sport_result_ds')->where("stype='bb' and status=0")->count();
        $data['bb_zhgg'] = M('sport_result_zhgg')->where("stype='bb' and status=0")->count();

        //早盘-足球
        $data['fu_ds']   = M('sport_result_ds')->where("stype='ft' and status=0")->count();
        $data['fu_zhgg'] = M('sport_result_zhgg')->where("stype='ft' and status=0")->count();
        $data['fu_bd']   = M('sport_result_bd')->where("status=0")->count();
        $data['fu_zrq']  = M('sport_result_zrq')->where("status=0")->count();
        $data['fu_bqs']  = M('sport_result_bqs')->where("status=0")->count();
        //早盘-篮球

        $data['bb_fu_ds']   = M('sport_result_ds')->where("stype='bb' and status=0")->count();
        $data['bb_fu_zhgg'] = M('sport_result_zhgg')->where("stype='bb' and status=0")->count();

        $this->ajaxReturn($data);
    }
    public function bb()
    {

        $btype = $_GET['btype'];
        if (empty($btype)) {
            $btype = 'gq';
        }

        //联赛
        $leagues = M('sport_league')->where("is_show=1 and stype='bb'")->select();
        $this->assign('leagues', $leagues);

        $result = M('sport_result_' . $btype); // 实例化User对象
        $count  = $result->where("status=0 and stype='bb'")->count(); // 查询满足要求的总记录数
        $Page   = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show   = $Page->show(); // 分页显示输出
        $list   = $result->where("status=0 and stype='bb'")->limit($Page->firstRow . ',' . $Page->listRows)->select();

        foreach ($list as $key => $value) {
            $list_new[$value['league_id']]['list'][]     = $value;
            $list_new[$value['league_id']]['match_name'] = $value['match_name'];

            //     if($value['final_score']!=''){
            //     $list_new[$value['league_id']]['list'][]['score']=$value['final_score'];
            // }else{
            //     $list_new[$value['league_id']]['list'][]['score']="上35'<br><span>2 - 0</span>";
            //     //$list[$k]['score']=$v['half_score'];
            // }

        }
        //print_r($list_new);exit;
        $this->assign('list', $list_new);
        $this->assign('page', $show); // 赋值分页输出

        $this->display('bb_' . $btype);
    }

    //早盘-足球
    public function fu()
    {

        $btype = $_GET['btype'];
        if (empty($btype)) {
            $btype = 'gq';
        }

        //联赛
        $leagues = M('sport_league')->where("is_show=1 and stype='ft'")->select();
        $this->assign('leagues', $leagues);

        $result = M('sport_result_' . $btype); // 实例化User对象
        $count  = $result->where("status=0 and stype='ft'")->count(); // 查询满足要求的总记录数
        $Page   = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show   = $Page->show(); // 分页显示输出
        $list   = $result->where("status=0 and stype='ft'")->limit($Page->firstRow . ',' . $Page->listRows)->select();

        foreach ($list as $key => $value) {
            $list_new[$value['league_id']]['list'][]     = $value;
            $list_new[$value['league_id']]['match_name'] = $value['match_name'];

            //     if($value['final_score']!=''){
            //     $list_new[$value['league_id']]['list'][]['score']=$value['final_score'];
            // }else{
            //     $list_new[$value['league_id']]['list'][]['score']="上35'<br><span>2 - 0</span>";
            //     //$list[$k]['score']=$v['half_score'];
            // }

        }
        //print_r($list_new);exit;
        $this->assign('list', $list_new);
        $this->assign('page', $show); // 赋值分页输出

        $this->display('ft_' . $btype);
    }
//早盘-篮球
    public function fu_bb()
    {

        $btype = $_GET['btype'];
        if (empty($btype)) {
            $btype = 'gq';
        }

        //联赛
        $leagues = M('sport_league')->where("is_show=1 and stype='bb'")->select();
        $this->assign('leagues', $leagues);

        $result = M('sport_result_' . $btype); // 实例化User对象
        $count  = $result->where("status=0 and stype='bb'")->count(); // 查询满足要求的总记录数
        $Page   = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show   = $Page->show(); // 分页显示输出
        $list   = $result->where("status=0 and stype='bb'")->limit($Page->firstRow . ',' . $Page->listRows)->select();

        foreach ($list as $key => $value) {
            $list_new[$value['league_id']]['list'][]     = $value;
            $list_new[$value['league_id']]['match_name'] = $value['match_name'];

            //     if($value['final_score']!=''){
            //     $list_new[$value['league_id']]['list'][]['score']=$value['final_score'];
            // }else{
            //     $list_new[$value['league_id']]['list'][]['score']="上35'<br><span>2 - 0</span>";
            //     //$list[$k]['score']=$v['half_score'];
            // }

        }
        //print_r($list_new);exit;
        $this->assign('list', $list_new);
        $this->assign('page', $show); // 赋值分页输出

        $this->display('bb_' . $btype);
    }

    public function order()
    {
        $match_id = $_GET['match_id'];

        $info               = D('Member')->getOneMember($_SESSION['member_id']);
        $list               = M('sport_result_ds')->where("match_id='" . $match_id . "'")->find();
        $list['half_score'] = "上35'<br><span>2 - 0</span>";

        $btype = $_GET['btype'];

        $explode = explode('_', $btype);
        //上半场、全场
        $half = $explode[0];
        if ($half == 'fh') {
            $half  = '半场';
            $btype = $explode[1];
            //主客
            $hc = $explode[2];
        } else {
            $half  = '全场';
            $btype = $explode[0];
            //主客
            $hc = $explode[1];
        }
        //当前赔率的投注名称
        $order['odds_name'] = $list[$_GET['btype'] . '_name'];

        //赔率计算方式
        $odds_type = 0;

        if ($hc == 'c') {
            $order['odds_name'] = $list['away_team'];
        } elseif ($hc == 'd') {
            $order['odds_name'] = '和';
        } else {
            $order['odds_name'] = $list['home_team'];
        }
        if ($btype == 'dy') {
            $order['wanfa'] = $half . '-独赢<br>';
            $odds_type      = 1;
        } elseif ($btype == 'rq') {
            $order['wanfa'] = $half . '-让球-<font color="green">' . $list[$_GET['btype'] . '_name'] . '</font><br>';

        } elseif ($btype == 'ds') {
            $order['wanfa'] = $half . '-单双<br>';
            if ($hc == 'h') {
                $order['odds_name'] = '单';
            } else {
                $order['odds_name'] = '双';
            }
        } elseif ($btype == 'dx') {
            $order['wanfa'] = $half . '-大小<br>';
            if ($hc == 'h') {
                $order['odds_name'] = '大';
            } else {
                $order['odds_name'] = '小';
            }
        }

        $type = $_GET['type'];
        if ($type == 'bd') {
            //波胆玩法
            $odds_type = 1;

            $first_score  = substr($explode[0], 2, 1);
            $second_score = substr($explode[0], 3, 1);
            if ($explode[1] == 'c') {
                $a            = $first_score;
                $b            = $second_score;
                $first_score  = $b;
                $second_score = $a;
            }
            $score              = $first_score . ':' . $second_score;
            $order['odds_name'] = '比分 ' . $score;
            $list               = M('sport_result_bd')->where("match_id='" . $match_id . "'")->find();

        } elseif ($type == 'zrq') {
            //总让球玩法
            $odds_type = 1;
            if ($btype == 'rq01') {
                $score = ' 0~1';
            } elseif ($btype == 'rq23') {
                $score = ' 2~3';
            } elseif ($btype == 'rq46') {
                $score = ' 4~6';
            } else {
                $score = ' 7up';
            }
            $order['odds_name'] = '入球数 ' . $score;
            $list               = M('sport_result_zrq')->where("match_id='" . $match_id . "'")->find();

        } elseif ($type == 'bqs') {
            //半全场玩法
            $odds_type = 1;
            $b1        = substr($btype, 0, 1);
            $b2        = substr($btype, 1, 1);
            switch ($b1) {
                case 'h':
                    $b1 = '主';
                    break;
                case 'c':
                    $b1 = '客';
                    break;
                default:
                    $b1 = '和';
                    break;
            }
            switch ($b2) {
                case 'h':
                    $b2 = '主';
                    break;
                case 'c':
                    $b2 = '客';
                    break;
                default:
                    $b2 = '和';
                    break;
            }

            $order['odds_name'] = $b1 . '/' . $b2;
            $list               = M('sport_result_bqs')->where("match_id='" . $match_id . "'")->find();

        } elseif ($type == 'zhgg') {

        }

        $order['match_id']   = $_GET['match_id'];
        $order['match_name'] = $list['match_name'];
        $order['home_team']  = $list['home_team'];
        $order['away_team']  = $list['away_team'];

        $order['odds'] = $list[$_GET['btype']];

        $order['stype'] = $_GET['stype'];
        $order['btype'] = $_GET['btype'];
        $order['type']  = $_GET['type'];
        $this->assign('info', $info);
        $this->assign('odds_type', $odds_type);
        $this->assign('order', $order);
        $this->display();
    }
    //综合过关订单
    public function order_zhgg()
    {
        $match_id   = $_GET['match_id'];
        $type       = $_GET['type'];
        $stype      = $_GET['stype'];
        $btype      = $_GET['btype'];
        $list       = M('sport_result_gq')->where("match_id='" . $match_id . "'")->find();
        $order_zhgg = cookie('order_zhgg');

        $order_zhgg = json_decode($order_zhgg, true);

        if ($order_zhgg == '') {
            $order_zhgg = array();
        }
        if (!empty($list)) {
            $key = $list['match_id'];
            //    $order_zhgg[$key]['type']=$type;
            $order_zhgg[$key] = $list;

            $explode = explode('_', $btype);
            //上半场、全场
            $half = $explode[0];
            if ($half == 'fh') {
                $half  = '半场';
                $btype = $explode[1];
            } else {
                $half  = '全场';
                $btype = $explode[0];
            }
            //当前赔率的投注名称
            $order_zhgg[$key]['odds_name'] = $list[$_GET['btype'] . '_name'];

            //赔率计算方式
            $odds_type = 0;
            if ($btype == 'dy') {
                $order_zhgg[$key]['wanfa'] = $half . '-独赢<br>';
                $odds_type                 = 1;
            } elseif ($btype == 'rq') {
                $order_zhgg[$key]['wanfa'] = $half . '-让球-<font color="green">' . $list[$_GET['btype'] . '_name'] . '</font><br>';
                if ($_GET['btype'] == 'rq_c') {
                    $order_zhgg[$key]['odds_name'] = $list['away_team'];
                } else {
                    $order_zhgg[$key]['odds_name'] = $list['home_team'];
                }

            } elseif ($btype == 'ds') {
                $order_zhgg[$key]['wanfa'] = $half . '-单双<br>';
            } elseif ($btype == 'dx') {
                $order_zhgg[$key]['wanfa'] = $half . '-大小<br>';
            }

            $order_zhgg[$key]['odds'] = $list[$_GET['btype']];

        }
        $odds = 1;
        foreach ($order_zhgg as $k => $v) {
            $odds *= $v['odds'];
        }
        $odds            = sprintf('%.2f', $odds);
        $order_zhgg_json = json_encode($order_zhgg);
        cookie('order_zhgg', $order_zhgg_json);
        $count = count($order_zhgg);
        $this->assign('list', $order_zhgg);
        $this->assign('count', $count);
        $this->assign('odds', $odds);
        $this->display();
    }
    //下注处理
    public function doorder()
    {
        $low_limit         = 1.00;
        $hight_limit       = 20000;
        $gold              = $_POST['gold'];
        $member_money      = M('member')->where('member_id=' . $_SESSION['member_id'])->getField('member_money');
        $info              = M('sport_result_' . $_POST['type'])->where('match_id=' . $_POST['match_id'])->find();
        $data['btype']     = $_POST['btype'];
        $data['m_id']      = $_SESSION['member_id'];
        $data['type']      = $_POST['type'];
        $data['stype']     = $_POST['stype'];
        $data['match_id']  = $_POST['match_id'];
        $data['money']     = $_POST['gold'];
        $data['odds']      = $info[$_POST['btype']];
        $data['wanfa']     = preg_replace('/<br>/', '', $_POST['wanfa']);
        $data['home_team'] = $info['home_team'];
        $data['away_team'] = $info['away_team'];
        $data['buy_name']  = $_POST['odds_name'];

        $explode = explode('_', $_POST['btype']);
        if ($explode[0] == 'dy' || $explode[1] == 'dy') {
            //赔率减一
            $win = ($data['odds'] - 1) * $gold;
        } else {
            $win = $data['odds'] * $gold;
        }

        $data['win_money'] = $win;
        if ($info) {
            $ajaxdata['msg']    = '投注金额：' . $gold . '\n可赢金额：' . $win . '\n确定要投注吗？';
            $ajaxdata['result'] = 1;
        } else {
            $ajaxdata['result'] = 0;
        }

        if ($member_money < $gold) {
            $ajaxdata['msg'] = '您的余额不足';
        }
        if ($gold < $low_limit) {
            $ajaxdata['msg'] = '投注金额不能低于' . $low_limit;
        }
        if ($hight_limit < $gold) {
            $ajaxdata['msg'] = '投注金额不能高于' . $hight_limit;
        }

        $data['add_time'] = time();
        if ($_POST['queren'] == 1) {
            $result = M('sport_order')->add($data);
            if ($result > 0) {
                $ajaxdata['status'] = 1;
            } else {
                $ajaxdata['status'] = 0;
                $ajaxdata['msg']    = '订单异常';
            }
        }

        $this->ajaxReturn($ajaxdata);

    }
    public function bet()
    {

        $this->display();
    }
    public function order_list()
    {
        $list = M('sport_order')->where('status=0')->order('id desc ')->limit(0, 10)->select();
        $this->assign('list', $list);
        $this->display();
    }
    public function check_session()
    {
        if ($_SESSION['member_id'] > 0) {
            $data['status'] = 1;
            $this->ajaxReturn($data);
        }
    }
    /**
     *  个人资讯
     */
    public function info()
    {
        $info = M('member')->field('member_name,member_mobile,add_time,last_login_time,member_money,member_f_money,status')->where('member_id=' . $_SESSION['member_id'])->find();

        $this->assign('info', $info);
        $this->display('member-info');
    }
    /**
     *  未结明细
     */
    public function bets()
    {
        $settled = $_GET['settled'];
        $type    = S('type_array');
        $lottery = S('lottry_array');
        if ($settled == true) {
            $map['status']  = 1;
            $time           = strtotime(date('y-m-d', time()));
            $map['js_time'] = array('gt', $time);
            // $map['add_time']=array('gt',$time);
        } else {
            $map['status'] = 0;
        }

        $map['m_id'] = $_SESSION['member_id'];

        $count = M('lottery_order')->where($map)->count(); // 查询满足要求的总记录数
        $Page  = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show  = $Page->show(); // 分页显示输出

        $list    = M('lottery_order')->where($map)->limit($Page->firstRow . ',' . $Page->listRows)->order('order_id desc')->select();
        $win     = 0;
        $sum     = 0;
        $tuishui = 0;
        foreach ($list as $k => $v) {
            /* $list[$k]['wanfa']='<span class="text">'.$type[$v['w_type']]['text'].$type[$v['w_type']][$v['t_type']].'</span>@<span class="odds">'.$v['odds'].'</span>'; */
            $list[$k]['wanfa'] = '<span class="text">' . $v['w_name'] . $v['t_name'] . '</span>@<span class="odds">' . $v['odds'] . '</span>';
            if (substr($v['w_type'], 0, 2) == 'LM' || substr($v['w_type'], 0, 2) == 'LX' || substr($v['w_type'], 0, 2) == 'LW') {
                $list[$k]['wanfa'] .= '<br>' . $v['t_type'];
            }
            if ($v['is_winning'] == 1) {
                if ($v['win_money'] > 0) {
                    $list[$k]['win'] = $v['win_money'];
                    $win += $v['win_money'];
                } else {
                    $win += ($v['odds'] - 1) * $v['money'];
                    $list[$k]['win'] = ($v['odds'] - 1) * $v['money'];
                }

            } elseif ($v['is_winning'] == 2) {
                if (abs($v['win_money']) > 0) {
                    $win += $v['win_money'];

                    $list[$k]['win'] = $v['win_money'];
                } else {
                    $win -= $v['money'];
                    $list[$k]['win'] = '-' . $v['money'];
                }
                $tuishui += $v['rebate'];
            } else {
                $list[$k]['win'] = 0;
            }
            if ($v['status'] == 0) {
                $tuishui += $v['rebate'];
                $win += ($v['odds'] - 1) * $v['money'];
                $list[$k]['win'] = ($v['odds'] - 1) * $v['money'];
            }

            $list[$k]['c_name'] = $lottery[$v['c_id']]['text'];

            $sum += $v['money'];
        }

        $this->assign('sum_money', $sum);
        $this->assign('sum_win', $win);
        $this->assign('tuishui', $tuishui);
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display('member-bets');
    }
    /**
     *  报表查询
     */
    public function history()
    {
        //默认查询一个星期
        $begin = $_GET['begin'];
        $end   = $_GET['end'];
        if (empty($begin) || empty($end)) {
            $end           = time();
            $begin         = strtotime(date('Y-m-d', time())) - 7 * 86400;
            $_GET['begin'] = date('Y-m-d', $begin);
            $_GET['end']   = date('Y-m-d', $end);
        } else {
            $begin = strtotime($begin);
            $end   = strtotime($end) + 86400;
        }
        $map['add_time'] = array('between', array($begin, $end));
        //$map['dl_status']=1;
        $map['m_id'] = $_SESSION['member_id'];

        $count = M('lottery_order')->where($map)->count(); // 查询满足要求的总记录数
        $Page  = new \Think\Page($count, 25); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show  = $Page->show(); // 分页显示输出

        $list = M('lottery_order')->where($map)->limit($Page->firstRow . ',' . $Page->listRows)->order('order_id desc')->select();
        //$list=M('lottery_order')->where($map)->order('order_id desc')->select();
        $sum_num   = 0;
        $sum_money = 0.00;
        $sum_tui   = 0.00;
        $sum_win   = 0.00;
        foreach ($list as $k => $v) {
            $lose            = 0;
            $list[$k]['num'] = 1;
            $sum_num += 1;
            $sum_money += $v['money'];
            $sum_win -= $v['money'];
            if ($v['is_winning'] != 1) {
                $sum_tui += $v['rebate'];
                $list[$k]['win'] = -$v['money'];
            } else {
                $sum_win += $v['money'] * $v['odds'];
                $list[$k]['win'] = $v['money'] * ($v['odds'] - 1);
            }

        }

        $this->assign('begin', $_GET['begin']);
        $this->assign('end', $_GET['end']);
        $this->assign('sum_num', $sum_num);
        $this->assign('sum_money', $sum_money); //下注金额
        $this->assign('sum_tui', $sum_tui); //退水
        $this->assign('sum_win', $sum_win); //盈亏
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display('member-history');
    }

    /**
     *  开奖结果
     */
    public function dresult()
    {
        $lottery = S('lottry_array');
        //结果
        if (empty($_GET['date'])) {
            $_GET['date'] = date('Y-m-d', time());

        }
        switch ($_GET['lottery']) {
            case 'CQSSC':
                $_GET['lottery'] = 1;
                break;
            case 'XJSSC':
                $_GET['lottery'] = 2;
                break;
            case 'TJSSC':
                $_GET['lottery'] = 3;
                break;
            case 'BJPK10':
                $_GET['lottery'] = 4;
                break;
            case 'XYFT':
                $_GET['lottery'] = 5;
                break;
            case 'GDKLSF':
                $_GET['lottery'] = 6;
                break;
            case 'GXK3':
                $_GET['lottery'] = 7;
                break;
            case 'XYNC':
                $_GET['lottery'] = 8;
                break;
            case 'BJKL8':
                $_GET['lottery'] = 9;
                break;
            case 'GXKLSF':
                $_GET['lottery'] = 10;
                break;
            case 'PCEGG':
                $_GET['lottery'] = 11;
                break;
            case 'HK6':
                $_GET['lottery'] = 12;
                break;
            case 'FFC':
                $_GET['lottery'] = 13;
                break;

        }
        $time  = strtotime($_GET['date']);
        $time2 = $time + 86400;
        if ($_GET['lottery'] == 12) {

        } else {
            $map['add_time'] = array('between', array($time, $time2));
        }

        $map['c_id'] = $_GET['lottery'];

        $list    = M('lottery_results')->where($map)->order('id desc')->select();
        $weekday = array('日', '一', '二', '三', '四', '五', '六');
        foreach ($list as $k => $v) {
            $list[$k]['time']     = date('m-d', $v['add_time']) . $weekday[date('w', $v['add_time'])] . date('H:i', $v['add_time']);
            $list[$k]['add_time'] = date('Y-m-d', $v['add_time']);
            $list[$k]['number']   = explode(',', $v['lottery_result']);
            $array                = explode(',', $v['lottery_result']);
            $list[$k]['number']   = $array;
            $sum                  = array_sum($array);
            $list[$k]['sum']      = $sum;
            $list[$k]['td']       = $this->get_result($_GET['lottery'], $array, $sum);

        }
        $this->assign('list', $list);
        $this->assign('c_id', $_GET['lottery']);
        $this->assign('date', $_GET['date']);
        $this->assign('lottery', $lottery);
        $this->display('member-dresult-' . $_GET['lottery']);
    }
    /**
     *
     */
    public function account()
    {
        //pritn_r($_SESSION['member_id']);exit;
        header('Content-type:text/json');
        $info = D('Member')->getOneMember($_SESSION['member_id']);

        $betting = M('lottery_order')->where('m_id=' . $_SESSION['member_id'] . ' and status=0')->sum('money');
        if (empty($betting)) {
            $betting = 0;
        }
        $data["balance"] = $info['member_money'];
        $data["betting"] = $betting;
        $data["bonus"]   = 0;
        $data["freeze"]  = $info['member_f_money'];
        echo json_encode($data);exit(0);
    }

    public function deposit()
    {
        redirect('/index.php/Payment/deposit', 0);

    }

    /* 跳转 end*/

/**
 *
 */
    public function ntime()
    {
        //pritn_r($_SESSION['member_id']);exit;
        list($t1, $t2) = explode(' ', microtime());
        echo $t2 . '' . ceil(($t1 * 1000));exit(0);
        // echo json_encode($data);exit(0);
    }

    public function load()
    {

        $c_type = $_GET['lottery'];
        $w_type = $_GET['page'];
        switch ($c_type) {
            //幸运飞艇
            case 'XYFT':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/xyft-lm');
                        break;
                    case '110':
                        $this->display('Load/xyft-110');
                        break;
                    case 'gy':
                        $this->display('Load/xyft-gy');
                        break;
                    default:
                        break;
                }
                break;
            case 'BJPK10':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/pk10-lm');
                        break;
                    case '110':
                        $this->display('Load/pk10-110');
                        break;
                    case 'gy':
                        $this->display('Load/pk10-gy');
                        break;
                    default:
                        break;
                }
                break;
            case 'CQSSC':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/cqssc-lm');
                        break;
                    case 'ball':
                        // print_r($_GET['index']);exit;
                        //  print_r($_SESSION);exit;.
                        $_SESSION['index'] = $_GET['index'];
                        //$string='B'.$_GET['index'].',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $string = 'B' . $_GET['index'] . ',DX' . $_GET['index'] . ',DS' . $_GET['index'] . ',ZDX,ZDS,LH,TS1,TS2,TS3';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        // print_r($_SESSION);exit;
                        $this->display('Load/cqssc-ball');
                        break;
                    default:
                        break;
                }
                break;
            //新疆时时彩
            case 'XJSSC':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/xjssc-lm');
                        break;
                    case 'ball':
                        // print_r($_GET['index']);exit;
                        //  print_r($_SESSION);exit;.
                        $_SESSION['index'] = $_GET['index'];
                        //$string='B'.$_GET['index'].',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $string = 'B' . $_GET['index'] . ',DX' . $_GET['index'] . ',DS' . $_GET['index'] . ',ZDX,ZDS,LH,TS1,TS2,TS3';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        // print_r($_SESSION);exit;
                        $this->display('Load/xjssc-ball');
                        break;
                    default:
                        break;
                }
                break;
            //天津时时彩
            case 'TJSSC':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/tjssc-lm');
                        break;
                    case 'ball':
                        // print_r($_GET['index']);exit;
                        //  print_r($_SESSION);exit;.
                        $_SESSION['index'] = $_GET['index'];
                        // $string='B'.$_GET['index'].',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $string = 'B' . $_GET['index'] . ',DX' . $_GET['index'] . ',DS' . $_GET['index'] . ',ZDX,ZDS,LH,TS1,TS2,TS3';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        // print_r($_SESSION);exit;
                        $this->display('Load/tjssc-ball');
                        break;
                    default:
                        break;
                }
                break;
            //重庆幸运农场
            case 'XYNC':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/cqxync-lm');
                        break;
                    case 'ball':
                        $_SESSION['index'] = $_GET['index'];
                        //$string='B'.$_GET['index'].',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $string = 'B' . $_GET['index'] . ',DX' . $_GET['index'] . ',DS' . $_GET['index'] . ',WDX' . $_GET['index'] . ',HDS' . $_GET['index'] . ',FW' . $_GET['index'] . ',ZFB' . $_GET['index'] . ',LH' . $_GET['index'] . '';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        $this->display('Load/cqxync-ball');
                        break;
                    case 'balls':
                        $this->display('Load/cqxync-balls');
                        break;
                    case 'zm':
                        $this->display('Load/cqxync-zm');
                        break;
                    case 'mp':
                        $this->display('Load/cqxync-mp');
                        break;
                    default:
                        break;
                }
                break;
            //广东快乐十分
            case 'GDKLSF':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/gdklsf-lm');
                        break;
                    case 'ball':
                        $_SESSION['index'] = $_GET['index'];
                        //$string='B'.$_GET['index'].',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $string = 'B' . $_GET['index'] . ',DX' . $_GET['index'] . ',DS' . $_GET['index'] . ',WDX' . $_GET['index'] . ',HDS' . $_GET['index'] . ',FW' . $_GET['index'] . ',ZFB' . $_GET['index'] . ',LH' . $_GET['index'] . '';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        $this->display('Load/gdklsf-ball');
                        break;
                    case 'balls':
                        $this->display('Load/gdklsf-balls');
                        break;
                    case 'zm':
                        $this->display('Load/gdklsf-zm');
                        break;
                    case 'mp':
                        $this->display('Load/gdklsf-mp');
                        break;
                    default:
                        break;
                }
                break;
            //广西快三
            case 'GXK3':
                switch ($w_type) {
                    case 'all':
                        $this->display('Load/gxk3-all');
                        break;
                    case 'yxx':
                        $this->display('Load/gxk3-yxx');
                        break;
                    default:
                        break;
                }
                break;
            //PC蛋蛋
            case 'PCEGG':
                $this->display('Load/pcegg');
                break;
            //北京快8
            case 'BJKL8':
                switch ($w_type) {
                    case 'all':
                        $this->display('Load/bjkl8-all');
                        break;
                    case 'balls':
                        $this->display('Load/bjkl8-zm');
                        break;
                    default:
                        break;
                }
                break;
            //广西快乐十分
            case 'GXKLSF':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/gxklsf-lm');
                        break;
                    case '15':
                        $this->display('Load/gxklsf-15');
                        break;
                    case 'ball':
                        $_SESSION['index'] = $_GET['index'];
                        //$string='B1,SB1,YFLSX1,YDX1,YDS1,YWDX1,YHDS1';
                        $string = 'B' . $_GET['index'] . ',SB' . $_GET['index'] . ',YFLSX' . $_GET['index'] . ',YDX' . $_GET['index'] . ',YDS' . $_GET['index'] . ',YWDX' . $_GET['index'] . ',YHDS' . $_GET['index'];
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        $this->display('Load/gxklsf-ball1');
                        break;
                    default:
                        break;
                }
                break;
            //六合彩
            case 'HK6':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/hk6-lm');
                        break;
                    case 'tm':
                        if ($_GET['index']) {
                            $_SESSION['index'] = $_GET['index'];
                        } else {
                            $_SESSION['index'] = 'A';
                        }
                        $string = 'TM' . $_SESSION['index'] . ',DX,DS,HDS,HDX,WDX,TDXDS,SB';
                        $this->assign('games', $string);
                        $this->assign('num', $_SESSION['index']);
                        $this->display('Load/hk6-tm');
                        break;
                    case 'sb':
                        $this->display('Load/hk6-sb');
                        break;
                    case '12sx':

                        $this->display('Load/hk6-12sx');
                        break;
                    case 'hx':
                        $this->display('Load/hk6-hx');
                        break;
                    case 'zma':

                        $this->display('Load/hk6-zma');
                        break;
                    case 'zmt':
                        if ($_GET['index']) {
                            $_SESSION['index'] = $_GET['index'];
                        } else {
                            $_SESSION['index'] = '1';
                        }
                        $string = 'ZMT' . $_SESSION['index'] . ',DX,DS,HDS,ZMDS' . $_SESSION['index'] . ',ZMDX' . $_SESSION['index'] . ',ZHDS' . $_SESSION['index'] . ',ZMSB' . $_SESSION['index'] . '';
                        $this->assign('games', $string);
                        $this->assign('num', $_SESSION['index']);

                        $this->display('Load/hk6-zmt');
                        break;
                    case 'zm16':
                        $this->display('Load/hk6-zm16');
                        break;
                    case 'wx':
                        $this->display('Load/hk6-wx');
                        break;
                    case 'yx':
                        $this->display('Load/hk6-yx');
                        break;
                    case 'zx':
                        $this->display('Load/hk6-zx');
                        break;
                    case 'zxbz':
                        $this->display('Load/hk6-zxbz');
                        break;
                    case 'dpelx':
                        if ($_GET['index']) {
                            $_SESSION['index'] = $_GET['index'];
                        } else {
                            $_SESSION['index'] = '2';
                        }

                        $string = 'LX' . $_SESSION['index'];
                        if ($_SESSION['index'] == 2) {
                            $str = '二连肖';
                        } elseif ($_SESSION['index'] == 3) {
                            $str = '三连肖';
                        } elseif ($_SESSION['index'] == 4) {
                            $str = '四连肖';
                        } elseif ($_SESSION['index'] == 5) {
                            $str = '五连肖';
                        }
                        $this->assign('num', $_SESSION['index']);
                        $this->assign('games', $string);
                        $this->assign('str', $str);

                        $this->display('Load/hk6-dpelx');

                        break;
                    case 'dplw':
                        if ($_GET['index']) {
                            $_SESSION['index'] = $_GET['index'];
                        } else {
                            $_SESSION['index'] = '2';
                        }

                        $string = 'LW' . $_SESSION['index'];
                        if ($_SESSION['index'] == 2) {
                            $str = '二连尾';
                        } elseif ($_SESSION['index'] == 3) {
                            $str = '三连尾';
                        } elseif ($_SESSION['index'] == 4) {
                            $str = '四连尾';
                        } elseif ($_SESSION['index'] == 5) {
                            $str = '五连尾';
                        }
                        $this->assign('num', $_SESSION['index']);
                        $this->assign('games', $string);
                        $this->assign('str', $str);
                        $this->display('Load/hk6-dpelw');

                        break;
                    case 'mp':
                        $this->display('Load/hk6-mp');
                        break;
                    case 'zsx':
                        $this->display('Load/hk6-zsx');
                        break;

                    default:
                        break;
                }
                break;

            case 'FFC':
                switch ($w_type) {
                    case 'lm':
                        $this->display('Load/ffc-lm');
                        break;
                    case 'ball':
                        // print_r($_GET['index']);exit;
                        //  print_r($_SESSION);exit;.
                        $_SESSION['index'] = $_GET['index'];
                        $string            = 'B' . $_GET['index'] . ',DX1,DS1,ZDX,ZDS,LH,TS1,TS2,TS3';
                        $this->assign('games', $string);
                        $this->assign('num', $_GET['index']);
                        // print_r($_SESSION);exit;
                        $this->display('Load/ffc-ball');
                        break;
                    default:
                        break;
                }
                break;
            default:
                $this->display();
                break;

        }

    }
    /**
     *  密码修改
     */
    public function password()
    {
        if ($_POST) {
            $password    = $_POST['password'];
            $oldPassword = $_POST['oldPassword'];
            $code        = $_POST['code'];
            if ($code != $_SESSION['code']) {
                die(json_encode(array("success" => 0, "message" => '验证码错误')));
            }
            $pwd = M('member')->where('member_id=' . $_SESSION['member_id'])->getField('member_password');
            if ($pwd != md5($oldPassword)) {
                die(json_encode(array("success" => 0, "message" => '输入了错误的旧密码')));
            }
            $result = M('member')->where('member_id=' . $_SESSION['member_id'])->save(array('member_password' => md5($password)));
            if ($result >= 0) {
                die(json_encode(array("success" => 1, "message" => '密码修改成功')));
            } else {
                die(json_encode(array("success" => 0, "message" => '密码修改失败')));
            }
        }

        $this->display('member-password');
    }
    /**
     *  游戏规则
     */
    public function rule()
    {
        //规则列表 规则id=9
        $rule_list  = M('article')->field('article_id,article_title')->where('ac_id=9')->order('article_sort asc')->select();
        $article_id = $_GET['lottery'];
        if ($article_id > 0) {

        } else {
            $article_id = $rule_list[0]['article_id'];
        }
        //规则内容
        if ($article_id > 0) {
            $content = M('article')->where('article_id=' . $article_id)->getField('article_content');
        }

        $this->assign('list', $rule_list);
        $this->assign('content', $content);
        $this->assign('article_id', $article_id);
        $this->display('member-rule');
    }

    /**
     *  获取开奖结果
     */
    private function get_result($c_id, $list, $sum)
    {
        $td = '';
        switch ($c_id) {
            //重庆时时彩
            case 1:
                if ($sum <= 22) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }

                if ($list[0] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } elseif ($list[0] < $list[4]) {
                    $td .= '<td class="other GLH_H">虎</td>';
                } else {
                    $td .= '<td class="other GLHT_T">和</td>';
                }
                //$list=asort($list);

                //前三
                $numberArray[0] = $list[0];
                $numberArray[1] = $list[1];
                $numberArray[2] = $list[2];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //中三
                $numberArray[0] = $list[1];
                $numberArray[1] = $list[2];
                $numberArray[2] = $list[3];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //后三
                $numberArray[0] = $list[2];
                $numberArray[1] = $list[3];
                $numberArray[2] = $list[4];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                break;
            //新疆时时彩
            case 2:
                if ($sum <= 22) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }

                if ($list[0] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } elseif ($list[0] < $list[4]) {
                    $td .= '<td class="other GLH_H">虎</td>';
                } else {
                    $td .= '<td class="other GLHT_T">和</td>';
                }
                //$list=asort($list);

                //前三
                $numberArray[0] = $list[0];
                $numberArray[1] = $list[1];
                $numberArray[2] = $list[2];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //中三
                $numberArray[0] = $list[1];
                $numberArray[1] = $list[2];
                $numberArray[2] = $list[3];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //后三
                $numberArray[0] = $list[2];
                $numberArray[1] = $list[3];
                $numberArray[2] = $list[4];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                break;
            //天津时时彩
            case 3:
                if ($sum <= 22) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }

                if ($list[0] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } elseif ($list[0] < $list[4]) {
                    $td .= '<td class="other GLH_H">虎</td>';
                } else {
                    $td .= '<td class="other GLHT_T">和</td>';
                }
                //$list=asort($list);

                //前三
                $numberArray[0] = $list[0];
                $numberArray[1] = $list[1];
                $numberArray[2] = $list[2];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //中三
                $numberArray[0] = $list[1];
                $numberArray[1] = $list[2];
                $numberArray[2] = $list[3];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //后三
                $numberArray[0] = $list[2];
                $numberArray[1] = $list[3];
                $numberArray[2] = $list[4];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                break;
            //北京赛车PK10/  //幸运飞艇
            case 4:
            case 5:
                //冠亚军和
                $sum = $list[0] + $list[1];
                $td .= '<td class="other1">' . $sum . '</td>';
                if ($sum <= 11) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDX_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }
                if ($list[0] > $list[9]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[1] > $list[8]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[2] > $list[7]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[3] > $list[6]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[4] > $list[5]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                break;

            //广东快乐十分
            case 6:
                if ($sum < 83) {
                    $td .= '<td class="other GDX_X">小</td>';
                } elseif ($sum == 84) {
                    $td .= '<td class="other GDX_H">和</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }
                //和值尾数
                $w = substr($sum, -1);
                if ($w <= 4) {
                    $td .= '<td class="other1 GWDX_X">尾小</td>';

                } else {
                    $td .= '<td class="other1 GWDX_D">尾大</td>';
                }
                if ($list[0] > $list[7]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[1] > $list[6]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[2] > $list[5]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[3] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                break;
            //广西快3
            case 7:

                if ($sum <= 10 && $sum >= 4) {
                    $td .= '<td class="other GDX_X">小</td>';
                } elseif ($sum <= 17 && $sum >= 11) {
                    $td .= '<td class="other GDX_D">大</td>';
                } else {
                    $td .= '<td class="other GDX_H">和</td>';
                }
                break;
            //重庆幸运农场
            case 8:
                if ($sum < 83) {
                    $td .= '<td class="other GDX_X">小</td>';
                } elseif ($sum == 84) {
                    $td .= '<td class="other GDX_H">和</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }
                //和值尾数
                $w = substr($sum, -1);
                if ($w <= 4) {
                    $td .= '<td class="other1 GWDX_X">尾小</td>';

                } else {
                    $td .= '<td class="other1 GWDX_D">尾大</td>';
                }
                if ($list[0] > $list[7]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[1] > $list[6]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[2] > $list[5]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                if ($list[3] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                break;
            //北京快乐8
            case 9:
                if ($sum > 810) {
                    $td = '<td class="other GDX_D">大</td>';
                } elseif ($sum < 810) {
                    $td = '<td class="other GDX_X">小</td>';
                } else {
                    $td = '<td class="other GDX_H">和</td>';
                }
                //
                if ($sum % 2 == 0) {
                    $td .= '<td class="other GDS_S">双</td>';
                } else {
                    $td .= '<td class="other GDS_D">单</td>';
                }
                //
                if (696 <= $sum && $sum <= 763) {
                    $td .= '<td class="other GWX_2">木</td>';
                } elseif (764 <= $sum && $sum <= 855) {
                    $td .= '<td class="other GWX_3">水</td>';
                } elseif (856 <= $sum && $sum <= 923) {
                    $td .= '<td class="other GWX_4">火</td>';
                } elseif (923 <= $sum && $sum <= 1410) {
                    $td .= '<td class="other GWX_5">土</td>';
                } else {
                    $td .= '<td class="other GWX_1">金</td>';
                }
                if ($list[9] > 40) {
                    $td .= '<td class="other2 GQHH_D">后(多)</td>';
                } elseif ($list[10] < 40) {
                    $td .= '<td class="other2 GQHH_D">前(多)</td>';
                } else {
                    $td .= '<td class="other2 GQHH_T">前后(和)</td>';
                }
                //奇数个数
                $odd = 0;
                foreach ($list as $k => $v) {
                    if ($v % 2 == 1) {
                        $odd += 1;
                    }
                }
                if ($odd > 10) {
                    $td .= '<td class="other2 GDSH_D">单(多)</td>';
                } elseif ($odd < 10) {
                    $td .= '<td class="other2 GDSH_D">双(多)</td>';
                } else {
                    $td .= '<td class="other2 GDSH_T">单双(和)</td>';
                }

                break;
            //广西快乐十分
            case 10:
                if ($sum <= 54) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }
                //特码尾数
                $w = substr($list[4], -1);
                if ($w <= 4) {
                    if ($list[4] == 21) {
                        $td .= '<td class="other1 GWDX_H">和</td>';
                    } else {
                        $td .= '<td class="other1 GWDX_X">尾小</td>';
                    }

                } else {
                    $td .= '<td class="other1 GWDX_D">尾大</td>';
                }
                if ($list[0] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } else {
                    $td .= '<td class="other GLH_H">虎</td>';
                }
                break;

            //PC蛋蛋
            case 11:
                break;

            //香港六合彩
            case 12:
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDS_S">双</td>';
                }
                if ($sum >= 175) {

                    $td .= '<td class="other GDX_D">大</td>';
                } else {
                    $td .= '<td class="other GDX_X">小</td>';
                }
                //七色波
                $td .= $this->color($list);
                //特码
                $te = $list[6];
                if ($te % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDS_S">双</td>';
                }
                if ($te == 49) {
                    $td .= '<td class="TIE">和</td>';
                } elseif ($te <= 24) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDS_D">大</td>';
                }
                //个位
                $ge    = $te % 10;
                $shi   = $te / 10 % 10;
                $heshu = $ge + $shi;
                if ($te == 49) {
                    $td .= '<td class="TIE">和</td>';
                } elseif ($heshu % 2 == 1) {
                    $td .= '<td class="other GDS_D">合单</td>';
                } else {
                    $td .= '<td class="other GDS_S">合双</td>';
                }
                if ($te == 49) {
                    $td .= '<td class="TIE">和</td>';
                } elseif ($heshu >= 7) {
                    $td .= '<td class="other GHDX_D">合大</td>';
                } else {
                    $td .= '<td class="other GHDX_X">合小</td>';
                }
                //特尾
                $w = substr($list[6], -1);
                if ($te == 49) {
                    $td .= '<td class="TIE">和</td>';
                } elseif ($w > 4) {
                    $td .= '<td class="other GWDX_D">尾大</td>';
                } else {
                    $td .= '<td class="other GWDX_X">尾小</td>';
                }
                break;
            //纷纷彩
            case 13:
                if ($sum <= 22) {
                    $td .= '<td class="other GDX_X">小</td>';
                } else {
                    $td .= '<td class="other GDX_D">大</td>';
                }
                if ($sum % 2 == 1) {
                    $td .= '<td class="other GDS_D">单</td>';
                } else {
                    $td .= '<td class="other GDX_S">双</td>';
                }

                if ($list[0] > $list[4]) {
                    $td .= '<td class="other GLH_L">龙</td>';
                } elseif ($list[0] < $list[4]) {
                    $td .= '<td class="other GLH_H">虎</td>';
                } else {
                    $td .= '<td class="other GLHT_T">和</td>';
                }
                //$list=asort($list);

                //前三
                $numberArray[0] = $list[0];
                $numberArray[1] = $list[1];
                $numberArray[2] = $list[2];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //中三
                $numberArray[0] = $list[1];
                $numberArray[1] = $list[2];
                $numberArray[2] = $list[3];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                //后三
                $numberArray[0] = $list[2];
                $numberArray[1] = $list[3];
                $numberArray[2] = $list[4];
                //计算顺子、对子、半顺、豹子、杂六
                $resultArray = $this->calcGamePlayResult($numberArray);
                if ($resultArray[0] == 1) {
                    $td .= '<td class="other1 others GTS_3">对子</td>';
                } elseif ($resultArray[0] == 2) {
                    $td .= '<td class="other1 others GTS_4">豹子</td>';
                } elseif ($resultArray[1] == 1) {
                    $td .= '<td class="other1 others GTS_3">半顺</td>';
                } elseif ($resultArray[1] == 2) {
                    $td .= '<td class="other1 others GTS_4">顺子</td>';
                } else {
                    $td .= '<td class="other1 others GTS_4">杂六</td>';
                }
                break;
        }
        return $td;
    }

    /**
     * 计算顺子、对子、半顺、豹子、杂六
     *
     * @arguments array 数组
     *
     * @returns 数组下标0 对应豹子、对子   数组下标1 对应顺子、半顺、杂六
     */
    public function calcGamePlayResult($array)
    {
        sort($array);
        //存储计算结果
        $resultArray = array();

        //计算豹子、对子
        $resultArray[0] = $array[2] - $array[1] == 0 ? 1 : 0;
        $resultArray[0] = $array[1] - $array[0] == 0 ? ++$resultArray[0] : $resultArray[0];

        //计算顺子、半顺、杂六
        $resultArray[1] = $array[2] - $array[1] == 1 ? 1 : 0;
        $resultArray[1] = $array[1] - $array[0] == 1 ? ++$resultArray[1] : $resultArray[1];

        return $resultArray;
    }
    /**
     * 计算红波、蓝波、绿波
     *
     * @arguments array 数组
     *
     * @returns 数组下标0 对应红波、蓝波、绿波
     */
    public function color($array)
    {
        //红波
        $red = array(1, 2, 7, 8, 12, 13, 18, 19, 23, 24, 29, 30, 34, 35, 40, 45, 46);
        //蓝波
        $blue = array(3, 4, 9, 10, 14, 15, 20, 25, 26, 31, 36, 37, 41, 42, 47, 48);
        //绿波
        $green = array(5, 6, 11, 16, 17, 21, 22, 27, 28, 32, 33, 38, 39, 43, 44, 49);
        $r_num = 0;
        $b_num = 0;
        $g_num = 0;
        $num   = 1;
        foreach ($array as $k => $v) {
            if ($k == 6) {
                $num = 1.5;
            }
            if (in_array($v, $red)) {
                $r_num += $num;
            } elseif (in_array($v, $blue)) {
                $b_num += $num;
            } elseif (in_array($v, $green)) {
                $g_num += $num;
            }
        }

        if ($r_num > $b_num && $r_num > $g_num) {
            $result = '<td class="other G7SB_R">红波</td>';
        } elseif ($g_num > $b_num && $g_num > $r_num) {
            $result = '<td class="other G7SB_G">绿波</td>';

        } else {
            $result = '<td class="other G7SB_B">蓝波</td>';
        }
        if ($r_num == 3 && $b_num == 3) {
            $result = '<td class="other G7SB_TIE">和局</td>';
        } elseif ($g_num == 3 && $b_num == 3) {
            $result = '<td class="other G7SB_TIE">和局</td>';
        } elseif ($g_num == 3 && $r_num == 3) {
            $result = '<td class="other G7SB_TIE">和局</td>';
        }
        return $result;
    }

}
